<?php

class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
	protected function _initDb(){      
	      $dbOption['adapter'] = 'PDO_MYSQL';
	      $dbOption['params']['host'] = 'localhost';
	      $dbOption['params']['username'] = 'root';
	      $dbOption['params']['password'] = '';
	      $dbOption['params']['dbname'] = 'mail-manager';
	      $dbOption['params']['charset'] = 'utf8';
	      $db = Zend_Db::factory($dbOption['adapter'],$dbOption['params']);
	      $db->setFetchMode(Zend_Db::FETCH_ASSOC);
		  $db->query("SET NAMES 'utf8'");
    	  $db->query("SET CHARACTER SET 'utf8'");       
	      Zend_Registry::set('connectDb',$db);   //Đăng ký thông số kết nối DB   
	      Zend_Db_Table::setDefaultAdapter($db);

	   return $db; 
	}
	
	protected function _initAutoload()
{	
	// Ensure front controller instance is present
	$this->bootstrap('frontController');
	// Get frontController resource
	$this->_front = $this->getResource('frontController');
	
	// Add autoloader empty namespace
	$autoLoader = new Zend_Loader_Autoloader_Resource(
		array(
		'basePath' => APPLICATION_PATH,
		'namespace' => '',
		'resourceTypes' => array(
			'model' => array(
				'path' => 'models/',
				'namespace' => 'Model_'
				)
		),
	)
	);
	// Return it, so that it can be stored by the bootstrap
	return $autoLoader;
}

protected function _initView()
	{ 
		$view = new Zend_View;
		$view->setEncoding('UTF-8');
		
		// Set doctype and charset
		$view->doctype('XHTML1_TRANSITIONAL');
		$view->placeholder('charset')->set('utf-8');
		$view->baseUrl = $this->_front->getBaseUrl();
		return $view;
	}
    /**
     * Initialize the cache
     *
     * @return Zend_Cache_Core
     */
    protected function _initCache()
    {
        // Cache options
        $frontendOptions = array(
           'lifetime' => 1200,                      // Cache lifetime of 20 minutes
           'automatic_serialization' => true,
        );
        $backendOptions = array(
            'lifetime' => 3600,                     // Cache lifetime of 1 hour
            'cache_dir' => APPLICATION_PATH . '/cache/',   // Directory where to put the cache files
        );
     
        // Get a Zend_Cache_Core object
        $cache = Zend_Cache::factory('Core', 'File', $frontendOptions, $backendOptions);
        Zend_Registry::set('cache', $cache);
        // Return it, so that it can be stored by the bootstrap
        return $cache;
    } 		
	

	
}



